package com.example.kuaizu.service.imp;

import com.example.kuaizu.mapper.CleanProjectRemOveMapper;
import com.example.kuaizu.service.InCleanProjectRemOveService;
import kuaizu.common.exception.MassageException;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * @author: wangmx15
 * @date: 2025/10/4
 **/
@Service
@RequiredArgsConstructor
@Log4j2
public class CleanProjectRemOveService implements InCleanProjectRemOveService {
    private final CleanProjectRemOveMapper cleanProjectRemOveMapper;
    @Override
    @Transactional
    public void CleanProjectRemOveJob() {
        //查询已经删除的项目,并且还存在于订阅消息的表中的项目id
        List<Integer> ids = cleanProjectRemOveMapper.CleanProjectRemOveJob();
        if (CollectionUtils.isEmpty(ids)){
            return;
        }
        //根据id批量删除信息
        int count = cleanProjectRemOveMapper.deleteSubscribeMessageByIds(ids);
        if (count != ids.size()){
            log.error("删除信息失败,数据库删除条数跟查询数据不一致");
            throw new MassageException("删除信息失败");
        }
    }
}
